package com.erp.module.yuliaofreight

import android.content.Context
import android.util.Log
import com.erp.Interface.OnUserDataInterface
import com.erp.contacts.Contacts
import com.erp.contacts.Contacts.BOUNDARY
import com.erp.util.Httputil
import com.erp.util.Httputil.Call
import com.erp.util.Httputil.getparams
import org.xutils.http.RequestParams
import org.xutils.x

class YuliaoFreightModel {
    /**获取仓位余料*/
    fun getYuliao(context: Context, page: Int, pagesize: Int, onUserDataInterface: OnUserDataInterface, yfs_id:String,length:String,width:String,thickness:String,mc_2_name_mh:String,color:String,name:String) {
        val params = RequestParams(Contacts.YULIAO_FREIGHT_SPACE_GI)
        params.addBodyParameter("searchParams[yfs_id]", yfs_id)
        params.addBodyParameter("searchParams[length]", length)
        params.addBodyParameter("searchParams[width]", width)
        params.addBodyParameter("searchParams[thickness]", thickness)
        params.addBodyParameter("searchParams[mc_2_name_mh]", mc_2_name_mh)
        params.addBodyParameter("searchParams[color_color_mh]", color)
        params.addBodyParameter("searchParams[gi_name]", name)
        params.addBodyParameter("page", page.toString())
        params.addBodyParameter("pagesize", pagesize.toString())
        getparams(context, params)
        x.http().get<String>(params, Call(context, onUserDataInterface))
    }
    /**余料出仓*/
    fun outYuliao(context: Context,yfsg_id:String,rucangcode:String,onUserDataInterface :OnUserDataInterface){
        val params = RequestParams(Contacts.YULIAO_FREIGHT_SPACE_GI+"/out_yuliao")
        params.addBodyParameter("yfsg_id", yfsg_id,BOUNDARY)
        params.addBodyParameter("rucangcode", rucangcode,BOUNDARY)
        getparams(context, params)
        Httputil.addtoken(params)
        params.addHeader("ACCEPT", "application/json")
        x.http().post<String>(params, Call(context, onUserDataInterface))
    }

    /**余料取料*/
    fun fetchYuliao(context: Context,yfsg_id:String,length: String,rucangcode: String,onUserDataInterface :OnUserDataInterface){
        val params = RequestParams(Contacts.YULIAO_FREIGHT_SPACE_GI+"/fetch_yuliao")
        params.addBodyParameter("yfsg_id", yfsg_id,BOUNDARY)
        params.addBodyParameter("length", length,BOUNDARY)
        params.addBodyParameter("rucangcode", rucangcode,BOUNDARY)
        getparams(context, params)
        Httputil.addtoken(params)
        params.addHeader("ACCEPT", "application/json")
        x.http().post<String>(params, Call(context, onUserDataInterface))
    }
//    onSuccess
    /**余料入仓*/
    fun inYuliao(context: Context,yfs_id:String,gi_id:String,length:String,Width:String,Thickness:String,rucangcode: String,onUserDataInterface :OnUserDataInterface){
        val params = RequestParams(Contacts.YULIAO_FREIGHT_SPACE_GI+"/in_yuliao")
        params.addBodyParameter("gi_id", gi_id,BOUNDARY)
        params.addBodyParameter("yfs_id", yfs_id,BOUNDARY)
        params.addBodyParameter("length", length,BOUNDARY)
        params.addBodyParameter("width", Width,BOUNDARY)
        params.addBodyParameter("thickness", Thickness,BOUNDARY)
        params.addBodyParameter("rucangcode", rucangcode,BOUNDARY)
        getparams(context, params)
        Httputil.addtoken(params)
        params.addHeader("ACCEPT", "application/json")
        x.http().post<String>(params, Call(context, onUserDataInterface))
    }
    /**获取余料数据 */
    fun getBianmaData(context: Context,leibie:String, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.YULIAO_FREIGHT_SPACE_GI+"/"+leibie+"/freight_space")
        getparams(context, params)
        x.http().get<String>(params, Call(context, onUserDataInterface))
    }
    /**获取仓位数据 */
    fun getCangweiData(context: Context, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.YULIAO_FREIGHT_SPACE)
        getparams(context, params)
        x.http().get<String>(params, Call(context, onUserDataInterface))
    }
    /**创建仓位数据 */
    fun createCangweiData(context: Context,freight_space_name:String, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.YULIAO_FREIGHT_SPACE)
        params.addBodyParameter("freight_space_name", freight_space_name,BOUNDARY)
        params.addBodyParameter("", "",BOUNDARY)
        getparams(context, params)
        Httputil.addtoken(params)
        params.addHeader("ACCEPT", "application/json")
        x.http().post<String>(params, Call(context, onUserDataInterface))
    }
    /**修改仓位数据 */
    fun updateCangweiData(context: Context,yfs_id:String,freight_space_name:String ,onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.YULIAO_FREIGHT_SPACE+"/"+yfs_id+"/edit")
        params.addBodyParameter("freight_space_name", freight_space_name,BOUNDARY)
        params.addBodyParameter("", "",BOUNDARY)
        getparams(context, params)
        Httputil.addtoken(params)
        params.addHeader("ACCEPT", "application/json")
        x.http().post<String>(params, Call(context, onUserDataInterface))
    }
}